<template>
  <div id="app">

    <!-- 头部区域 -->
    <div class="header">
      <div class="header_left">
        <img src="@/assets/logo.png" alt="logo" class="logo">
        <span class="title">图书管理系统</span>
      </div>
      <el-dropdown class="logout" :hide-on-click="false">
        <span class="el-dropdown-link">
          {{admin.username}}<i class="el-icon-arrow-down el-icon--right"></i>
        </span>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item>
            <el-button type="text" @click="logout">退出登录</el-button>
          </el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </div>

    <!-- 头部以下 -->
    <div class="other">
      <!-- 侧边栏 -->
      <div class="aside">
        <el-menu :default-active="$route.path" router class="el-menu-vertical-demo aside_menu">
          <el-menu-item index="/layout">
            <i class="el-icon-eleme"></i>
            <span slot="title">首页</span>
          </el-menu-item>
          <el-submenu index="1">
            <template slot="title">
              <i class="el-icon-question"></i>
              <span>会员管理</span>
            </template>
            <el-menu-item index="/layout/user">
              <i class="el-icon-menu"></i>
              会员列表
            </el-menu-item>
            <el-menu-item index="/layout/add-user">
              <i class="el-icon-menu"></i>
              添加会员
            </el-menu-item>
          </el-submenu>
          <el-submenu index="2">
            <template slot="title">
              <i class="el-icon-question"></i>
              <span>管理员管理</span>
            </template>
            <el-menu-item index="/layout/admin">
              <i class="el-icon-menu"></i>
              管理员列表
            </el-menu-item>
            <el-menu-item index="/layout/add-admin">
              <i class="el-icon-menu"></i>
              添加管理员
            </el-menu-item>
          </el-submenu>
          <el-submenu index="3">
            <template slot="title">
              <i class="el-icon-question"></i>
              <span>图书分类管理</span>
            </template>
            <el-menu-item index="/layout/category">
              <i class="el-icon-menu"></i>
              图书分类列表
            </el-menu-item>
            <el-menu-item index="/layout/add-category">
              <i class="el-icon-menu"></i>
              添加图书分类
            </el-menu-item>
          </el-submenu>
          <el-submenu index="4">
            <template slot="title">
              <i class="el-icon-question"></i>
              <span>图书管理</span>
            </template>
            <el-menu-item index="/layout/book">
              <i class="el-icon-menu"></i>
              图书列表
            </el-menu-item>
            <el-menu-item index="/layout/add-book">
              <i class="el-icon-menu"></i>
              添加图书
            </el-menu-item>
          </el-submenu>
          <el-submenu index="5">
            <template slot="title">
              <i class="el-icon-question"></i>
              <span>借书管理</span>
            </template>
            <el-menu-item index="/layout/borrow">
              <i class="el-icon-menu"></i>
              借书列表
            </el-menu-item>
            <el-menu-item index="/layout/add-borrow">
              <i class="el-icon-menu"></i>
              添加借书
            </el-menu-item>
          </el-submenu>
          <el-submenu index="6">
            <template slot="title">
              <i class="el-icon-question"></i>
              <span>还书管理</span>
            </template>
            <el-menu-item index="/layout/retur">
              <i class="el-icon-menu"></i>
              还书列表
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </div>

      <!-- 中间主要部分数据 -->
      <div class="main">
        <router-view />
      </div>
    </div>

  </div>
</template>

<script>
export default {
  name: 'Layout',
  data() {
    return {
      admin: sessionStorage.getItem('admin') ? JSON.parse(sessionStorage.getItem('admin')) : {}
    }
  },
  methods:{
    logout(){
      sessionStorage.removeItem('admin');
      this.$router.push("/login");
    }
  }
}

</script>

<style lang="scss" scoped>
#app {

  width: 100vw;
  height: 100vh;
  overflow: hidden;

  // 头部
  .header {
    height: 60px;

    display: flex;
    justify-content: space-between;
    align-items: center;

    background-color: white;

    margin-bottom: 5px;

    .header_left {
      display: flex;
      align-items: center;

      .logo {
        width: 40px;

        margin: 0 20px;
      }

      .title {
        font-size: 25px;
        font-weight: bold;
      }
    }

    .logout {
      margin-right: 30px;
    }
  }

  // 侧边栏和主体部分
  .other {
    display: flex;

    // 侧边栏
    .aside {
      width: 200px;
      height: calc(100vh - 60px);
      overflow: hidden;
      background-color: white;

      margin-right: 5px;

      .aside_menu {
        height: 100%;
      }
    }

    // 主体
    .main {
      flex: 1;
      background-color: white;

      padding: 10px;
    }
  }
}
</style>
